{
    "kind": "Template",
    "apiVersion": "v1",
    "metadata": {
        "annotations": {
            "description": "Application template for ActiveMQ brokers using persistent storage."
        },
        "name": "amq6-persistent"
    },
    "labels": {
        "template": "amq6-persistent"
    },
    "parameters": [
        {
            "description": "ActiveMQ Release version, e.g. 6.2, etc.",
            "name": "AMQ_RELEASE",
            "value": "6.2"
        },
        {
            "description": "The name for the application.",
            "name": "APPLICATION_NAME",
            "value": "broker"
        },
        {
            "description": "Protocol to configure.  Only openwire is supported by EAP.  amqp, amqp+ssl, mqtt, stomp, stomp+ssl, and ssl are not supported by EAP",
            "name": "MQ_PROTOCOL",
            "value": "openwire"
        },
        {
            "description": "Queue names",
            "name": "MQ_QUEUES",
            "value": ""
        },
        {
            "description": "Topic names",
            "name": "MQ_TOPICS",
            "value": ""
        },
        {
            "description": "Size of persistent storage for database volume.",
            "name": "VOLUME_CAPACITY",
            "value": "512Mi"
        },
        {
            "description": "Broker user name",
            "name": "MQ_USERNAME",
            "from": "user[a-zA-Z0-9]{3}",
            "generate": "expression"
        },
        {
            "description": "Broker user password",
            "name": "MQ_PASSWORD",
            "from": "[a-zA-Z0-9]{8}",
            "generate": "expression"
        },
        {
            "description": "ActiveMQ Admin User",
            "name": "AMQ_ADMIN_USERNAME",
            "from": "user[a-zA-Z0-9]{3}",
            "generate": "expression"
        },
        {
            "description": "ActiveMQ Admin Password",
            "name": "AMQ_ADMIN_PASSWORD",
            "from": "[a-zA-Z0-9]{8}",
            "generate": "expression"
        },
        {
            "description": "Name of a secret containing SSL related files",
            "name": "AMQ_SECRET",
            "value": "amq-app-secret"
        },
        {
            "description": "SSL trust store filename",
            "name": "AMQ_TRUSTSTORE",
            "value": "broker.ts"
        },
        {
            "description": "SSL key store filename",
            "name": "AMQ_KEYSTORE",
            "value": "broker.ks"
        }
    ],
    "objects": [
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 5672,
                        "targetPort": 5672
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-amqp",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's amqp port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 5671,
                        "targetPort": 5671
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-amqp-ssl",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's amqp ssl port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 1883,
                        "targetPort": 1883
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-mqtt",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's mqtt port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 61613,
                        "targetPort": 61613
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-stomp",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's stomp port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 61612,
                        "targetPort": 61612
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-stomp-ssl",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's stomp ssl port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 61616,
                        "targetPort": 61616
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-tcp",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's tcp (openwire) port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 61617,
                        "targetPort": 61617
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-tcp-ssl",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's tcp ssl (openwire) port."
                }
            }
        },
        {
            "kind": "DeploymentConfig",
            "apiVersion": "v1",
            "metadata": {
                "name": "${APPLICATION_NAME}-amq",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                }
            },
            "spec": {
                "strategy": {
                    "type": "Recreate"
                },
                "triggers": [
                    {
                        "type": "ImageChange",
                        "imageChangeParams": {
                            "automatic": true,
                            "containerNames": [
                                "${APPLICATION_NAME}-amq"
                            ],
                            "from": {
                                "kind": "ImageStreamTag",
                                "namespace": "openshift",
                                "name": "jboss-amq-6:${AMQ_RELEASE}"
                            }
                        }
                    }
                ],
                "replicas": 1,
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                },
                "template": {
                    "metadata": {
                        "name": "${APPLICATION_NAME}-amq",
                        "labels": {
                            "deploymentConfig": "${APPLICATION_NAME}-amq",
                            "application": "${APPLICATION_NAME}"
                        }
                    },
                    "spec": {
                        "serviceAccount": "amq-service-account",
                        "containers": [
                            {
                                "name": "${APPLICATION_NAME}-amq",
                                "image": "jboss-amq-6",
                                "imagePullPolicy": "Always",
                                "volumeMounts": [
                                    {
                                        "name": "broker-secret-volume",
                                        "mountPath": "/etc/amq-secret-volume",
                                        "readOnly": true
                                    },
                                    {
                                        "mountPath": "/opt/amq/data/kahadb",
                                        "name": "${APPLICATION_NAME}-amq-pvol"
                                    }
                                ],
                                "readinessProbe": {
                                    "exec": {
                                        "command": [
                                            "/bin/bash",
                                            "-c",
                                            "curl -s -L -u ${AMQ_ADMIN_USERNAME}:${AMQ_ADMIN_PASSWORD} 'http://localhost:8161/hawtio/jolokia/read/org.apache.activemq:type=Broker,brokerName=*,service=Health/CurrentStatus' | grep -q '\"CurrentStatus\" *: *\"Good\"'"
                                        ]
                                    }
                                },
                                "ports": [
                                    {
                                        "name": "amqp",
                                        "containerPort": 5672,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "amqp-ssl",
                                        "containerPort": 5671,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "mqtt",
                                        "containerPort": 1883,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "stomp",
                                        "containerPort": 61613,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "stomp-ssl",
                                        "containerPort": 61612,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "tcp",
                                        "containerPort": 61616,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "tcp-ssl",
                                        "containerPort": 61617,
                                        "protocol": "TCP"
                                    }
                                ],
                                "env": [
                                    {
                                        "name": "AMQ_USER",
                                        "value": "${MQ_USERNAME}"
                                    },
                                    {
                                        "name": "AMQ_PASSWORD",
                                        "value": "${MQ_PASSWORD}"
                                    },
                                    {
                                        "name": "AMQ_PROTOCOLS",
                                        "value": "${MQ_PROTOCOL}"
                                    },
                                    {
                                        "name": "AMQ_QUEUES",
                                        "value": "${MQ_QUEUES}"
                                    },
                                    {
                                        "name": "AMQ_TOPICS",
                                        "value": "${MQ_TOPICS}"
                                    },
                                    {
                                        "name": "AMQ_ADMIN_USERNAME",
                                        "value": "${AMQ_ADMIN_USERNAME}"
                                    },
                                    {
                                        "name": "AMQ_ADMIN_PASSWORD",
                                        "value": "${AMQ_ADMIN_PASSWORD}"
                                    },
                                    {
                                        "name": "AMQ_KEYSTORE_TRUSTSTORE_DIR",
                                        "value": "/etc/amq-secret-volume"
                                    },
                                    {
                                        "name": "AMQ_TRUSTSTORE",
                                        "value": "${AMQ_TRUSTSTORE}"
                                    },
                                    {
                                        "name": "AMQ_KEYSTORE",
                                        "value": "${AMQ_KEYSTORE}"
                                    }
                                ]
                            }
                        ],
                        "volumes": [
                            {
                                "name": "broker-secret-volume",
                                "secret": {
                                    "secretName": "${AMQ_SECRET}"
                                }
                            },
                            {
                                "name": "${APPLICATION_NAME}-amq-pvol",
                                "persistentVolumeClaim": {
                                    "claimName": "${APPLICATION_NAME}-amq-claim"
                                }
                            }
                        ]
                    }
                }
            }
        },
        {
            "apiVersion": "v1",
            "kind": "PersistentVolumeClaim",
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-claim",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                }
            },
            "spec": {
                "accessModes": [ "ReadWriteOnce" ],
                "resources": {
                    "requests": {
                        "storage": "${VOLUME_CAPACITY}"
                    }
                }
            }
        }
    ]
}
